package com.rc.saas.mini.service.rc;

import com.rc.saas.mini.common.base.BaseMapper;
import com.rc.saas.mini.mapper.rc.RcMemberGainSettingRecordMapper;
import com.rc.saas.mini.model.rc.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RcMemberGainSettingRecordServiceImpl implements RcMemberGainSettingRecordService {
    @Autowired
    private RcMemberGainSettingRecordMapper rcMemberGainSettingRecordMapper;

    @Override
    public RcMemberGainSettingRecordMapper getMapper() {
        return rcMemberGainSettingRecordMapper;
    }

    @Override
    public void insertByList(List<RcMemberGainSetting> rcMemberGainSettingList, Long memberId) {
        for( RcMemberGainSetting rcMemberGainSetting:rcMemberGainSettingList){
            RcMemberGainSettingRecord rcMemberGainSettingRecord=new RcMemberGainSettingRecord();
            BeanUtils.copyProperties(rcMemberGainSetting,rcMemberGainSettingRecord);
            rcMemberGainSettingRecord.setMemberId(memberId);
            rcMemberGainSettingRecord.setCreatedTime(new Date());
            rcMemberGainSettingRecord.setLastUpdatedTime(new Date());
            rcMemberGainSettingRecordMapper.insertSelective(rcMemberGainSettingRecord);
        }
    }

    @Override
    public List<RcMemberGainSettingRecord> listCurrentByMemberId(Long memberId) {
        RcMemberGainSettingRecordExample example = new RcMemberGainSettingRecordExample();
        example.createCriteria().andMemberIdEqualTo(memberId).andStatusEqualTo("0");
        example.setOrderByClause("created_time desc");
        return rcMemberGainSettingRecordMapper.selectByExample(example);
    }
}
